import java.util.Stack;

public class MinStack {

        private Stack<Integer> stack;
        private Stack<Integer> MinStack;

        public MinStack() {
            stack = new Stack<>();
            MinStack = new Stack<>();
        }

        public void push(int val) {
            stack.push(val);

            if(MinStack.empty()){
                MinStack.push(val);
            }else{
                int peekV = stack.peek();
                if(peekV <= MinStack.peek()){
                    MinStack.push(peekV);
                }
            }
        }

        public void pop() {
            int val = stack.peek();
            if(val == MinStack.peek()){
                MinStack.pop();
            }
        }

        public int top() {
            if(stack.empty()){
                return -1;
            }
            return stack.peek();
        }

        public int getMin() {
            return MinStack.peek();
        }

}
